using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JTest.BUS;

namespace JTest.GUI
{
    public partial class frmSetting : Form
    {
        static SettingsDTO s;

        public frmSetting()
        {
            InitializeComponent();
            s = SettingsBUS.loadSettingInfoFromFile();
            nudSoCau.Value = s.NumberOfQuestion;
            dtpThoiGian.Value = new DateTime(2000,1,1,s.Hour,s.Minute,s.Second);
            // @LuongGV
            cmbDbase.DataSource = SettingsBUS.loadDbaseSources();
            cmbDbase.SelectedItem = s.Database;
        }

        private void nudSoCau_Enter(object sender, EventArgs e)
        {
            nudSoCau.Select(0, nudSoCau.Value.ToString().Length);
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            //lay info tu form
            s.NumberOfQuestion = Int32.Parse(nudSoCau.Value.ToString());
            s.Hour = dtpThoiGian.Value.Hour;
            s.Minute = dtpThoiGian.Value.Minute;
            s.Second = dtpThoiGian.Value.Second;
            s.Database = cmbDbase.SelectedItem.ToString();// @LuongGV
            //end lay info
            
            //save setting ra file
            SettingsBUS.saveSettingInfoToFile(s);
            //end save setting ra file

            //send thong tin setting qua main form
            //end send thong tin setting qua main form

            //close form
            this.Close();
        }


        /// <summary>
        /// Ham bat su kien value cua nudSoCau thay doi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nudSoCau_ValueChanged(object sender, EventArgs e)
        {
            if (nudSoCau.Value < 1)
            {
                nudSoCau.Value = 1;
            }
        }
    }
}